// pages/index/free/supervision.js
var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    city: '',
    cityid: '',
    proviceid: '',
    landing_page: '',
    list: [
      {num: 15,calss: '类',text: '前期审核'},
      {num: 12,calss: '项',text: '现场交底'},
      {num: 31,calss: '类',text: '隐蔽工程'},
      {num: 46,calss: '项',text: '中期工程'},
      {num: 35,calss: '类',text: '材料验收'},
      {num: 11,calss: '类',text: '竣工验收'}
    ],
    polist:[
      {
        title:'15类前期审核',
        child:[
          {listtext:'1.单价合理'},
          {listtext: '2.无重复收费'},
          {listtext: '3.工艺说明详细'},
          {listtext: '4.材料使用得当'},
          {listtext: '5.无多余项目'},
          {listtext: '6.收费明确'},
          {listtext: '7.报价与方案相符'},
          {listtext: '8.图纸全面'},
          {listtext: '9.复合图纸规范'},
          {listtext: '10.材料使用复合规范'},
          {listtext: '11.拆改无违规事项'},
          {listtext: '12.无安全隐患'},
          {listtext: '13.方案与原结构相对应'},
          {listtext: '14.造型方案可实现'},
          {listtext: '15.空间布置无使用障碍'}
        ]
      },
      {
        title: '12项工程交底',
        child: [
          {listtext: '1.地面具备施工条件'},
          {listtext: '2.上水出水畅通'},
          {listtext: '3.管道、风口完好'},
          {listtext: '4.顶面具备施工条件'},
          {listtext: '5.下水冲水通畅'},
          {listtext: '6.燃气表完好'},
          {listtext: '7.墙面具备施工条件'},
          {listtext: '8.门禁电话完好'},
          {listtext: '9.配电箱完好'},
          {listtext: '10.水表完好'},
          {listtext: '11.门窗拆除是否拆除'},
          {listtext: '12.电表完好'}
        ]
      },
      {
        title: '31项隐蔽工程',
        child: [
          {listtext: '1.墙体拆除'},
          {listtext: '2.管道安装'},
          {listtext: '3.接线分色'},
          {listtext: '4.结构改造（新建）'},
          {listtext: '5.轻体砖隔墙施工'},
          {listtext: '6.阀门、龙头安装'},
          {listtext: '7.弱电导线安装'},
          {listtext: '8.结构改造（拆除）'},
          {listtext: '9.骨架隔墙施工'},
          {listtext: '10.水管安装'},
          {listtext: '11.零线安装是否安全'},
          {listtext: '12.水路改造'},
          {listtext: '13.石膏板隔墙施工'},
          {listtext: '14.排水管材料'},
          {listtext: '15.管内导线总面积'},
          {listtext: '16.电路改造'},
          {listtext: '17.混水阀出水孔设置'},
          {listtext: '18.插座安装'},
          {listtext: '19.闭水实验'},
          {listtext: '20.洗手盆出水孔设置'},
          {listtext: '21.相序正确'},
          {listtext: '22.管道阀门口设置'},
          {listtext: '23.导线与燃气管距离'},
          {listtext: '24.水管开槽'},
          {listtext: '25.接线盒与燃气管距离'}
        ]
      },
      {
        title: '46项中期工程',
        child: [
          {listtext: '1.表面平整'},
          {listtext: '2.墙、顶面木楔间距'},
          {listtext: '3.清油木纹清晰'},
          {listtext: '4.水路工程'},
          {listtext: '5.立面垂直'},
          {listtext: '6.主龙骨间距'},
          {listtext: '7.清油漆无锤印、无刮痕'},
          {listtext: '8.电路工程'},
          {listtext: '9.阳角方正'},
          {listtext: '10.吊杆与主龙骨端部距离'},
          {listtext: '11.饰面板无损伤'},
          {listtext: '12.瓦工工程'},
          {listtext: '13.接缝高低'},
          {listtext: '14.吊杆间距'},
          {listtext: '15.混色漆颜色均匀一致'},
          {listtext: '16.木工工程'},
          {listtext: '17.接缝平直'},
          {listtext: '18.自攻钉距板边'},
          {listtext: '19.混色漆粉刷'},
          {listtext: '20.油工工程'},
          {listtext: '21.接缝宽度'},
          {listtext: '22.自攻钉间距'},
          {listtext: '23.混色漆刷纹通顺'},
          {listtext: '24.套割吻合，边缘整齐'},
          {listtext: '25.封板错缝安装'}
        ]
      },
      {
        title: '35类材料验收',
        child: [
          {listtext: '1.细木工板'},
          {listtext: '2.九厘板'},
          {listtext: '3.饰面板'},
          {listtext: '4.五厘板'},
          {listtext: '5.三合板'},
          {listtext: '6.密度板'},
          {listtext: '7.防火板'},
          {listtext: '8.刨花板'},
          {listtext: '9.木线条'},
          {listtext: '10.石膏线'},
          {listtext: '11.石膏板'},
          {listtext: '12.水泥板'},
          {listtext: '13.腻子粉'},
          {listtext: '14.玻璃胶'},
          {listtext: '15.白乳胶'},
          {listtext: '16.强锢'},
          {listtext: '17.石膏粉'},
          {listtext: '18.水暧管件'},
          {listtext: '19.油漆'},
          {listtext: '20.涂料'}
        ]
      },
      {
        title: '11项竣工验收',
        child: [
          {listtext: '1.水路工程'},
          {listtext: '2.电路工程'},
          {listtext: '3.木器工程'},
          {listtext: '4.墙面工程'},
          {listtext: '5.地面工程'},
          {listtext: '6.顶面工程'},
          {listtext: '7.现场卫生'},
          {listtext: '8.灯具安装'},
          {listtext: '9.面板、插座安装'},
          {listtext: '10.洁具安装'},
          {listtext: '11.地板铺装'}
        ]
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    that.viesupervision()
  },
  //加载来源页面
  viesupervision: function(e) {
    var that = this
    wx.request({
      url: app.apiUrl('c=zhaobiao/index&a=view_supervision'),
      data: {},
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
        //'content-type': 'application/json;charset=utf-8'
      },
      success: function(res) {
        console.log(res.data)
        var landing_page = res.data.datas.landing_page
        var bind_count = res.data.datas.bid_count
        var s1 = bind_count.substring(0, 1); //取前半部分
        var s2 = bind_count.substring(1, 2);
        var s3 = bind_count.substring(2, 3);
        var bids = bind_count.replace(/\b(0+)/gi, "")
        that.setData({
          landing_page: landing_page,
          num1: s1,
          num2: s2,
          num3: s3,
          count:bids
        })
      },
      fail: function() {
        console.log('请求错误')
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    var animation = wx.createAnimation({
      duration: 1000,
      timingFunction: "ease-in-out",
      delay: 0
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    var animatione = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease',
    })
    this.animation = animatione
    var next = true;
    //连续动画关键步骤
    setInterval(function() {
      if (next) {
        this.animation.scale(0.95).step()
        next = !next;
      } else {
        this.animation.scale(1).step()
        next = !next;
      }
      this.setData({
        animationDatas: animatione.export()
      })
    }.bind(this), 500)
  },
  //城市选择
  choosecity: function() {
    wx.navigateTo({
      url: '../public/custom/cucity',
    })
  },
  skipTop: function(e) {
    wx.pageScrollTo({
      scrollTop: 0
    })
  },

  settime: function () {
    var that = this
    setTimeout(function () {
      that.setData({
        alertmess: false
      })
    }, 2000)
  },
  //form表单跳转提交
  formSubmit: function(e) {
    var that = this
    var cityid = that.data.cityid
    var proviceid = that.data.proviceid
    var city = that.data.city
    var aleaname = e.detail.value.rqname
    var area = e.detail.value.area
    var tele = e.detail.value.tele
    var landing_page = that.data.landing_page
    var id = 2
    var title = '申请资料提交成功'
    var tsmall = '恭喜您，申请资料成功，我们将尽快与您联系!'
    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (city == '') {
      that.setData({
        alertmess: true,
        message: '请选择城市！'
      })
      that.settime()
      return false;
    } else if (aleaname == '') {
      that.setData({
        alertmess: true,
        message: '请填写小区名称！'
      })
      that.settime()
    } else if (area == '') {
      that.setData({
        alertmess: true,
        message: '请填写房屋面积！'
      })
      that.settime()
    } else if (tele == '') {
      that.setData({
        alertmess: true,
        message: '请输入手机号码！'
      })
      that.settime()
      return false;
    } else if (tele.length != 11) {
      that.setData({
        alertmess: true,
        message: '请重新输入号码！'
      })
      that.settime()
    } else if (!myreg.test(tele)) {
      that.setData({
        alertmess: true,
        message: '手机号错误,请重新输入！'
      })
      that.settime()
    }else {
      wx.request({
        url: app.apiUrl('c=zhaobiao/index&a=submit_house_inspection'),
        data: {
          phone: tele,
          address: aleaname,
          acreage: area,
          province: proviceid,
          city: cityid,
          landing_page: landing_page
        },
        method: 'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function(res) {
          var code = res.data.code
          var message = res.data.error
          if (code == 200) {
            wx: wx.navigateTo({
              url: 'applysuccess?data=' + [id, title, tsmall],
            })
          }
          else if (code == 400) {
            that.setData({
              alertmess: true,
              message: message
            })
            that.settime()
          }
        }
      })
    }
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
  },
  chooseclass: function(e) {
    var polist = this.data.polist
    var index = e.currentTarget.id;
    var polists = polist[index]
    console.log(index)
    console.log(polists)

    if(index==0||index==1){
      this.setData({
        tops:'144%'
      })
    } else if (index == 2 || index == 3){
      this.setData({
        tops: '154%'
      })
    }else{
      this.setData({
        tops: '164%'
      })
    }
    if(index==0||index==2||index==4){
      this.setData({
        direleft:true,
        direright:false
      })
    }else{
      this.setData({
        direleft: false,
        direright: true
      })
    }
    this.setData({
      polists:polists,
      showmodel:true
    })
  },
  closemodel:function(){
    this.setData({
      showmodel: false
    })
  },
  //跳到顶部
  skipTop: function(e) {
    wx.pageScrollTo({
      scrollTop: 0
    })
  }

})